﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Xml.Linq;
[ServiceContract]
interface ILEDSVCWIN
{
    [OperationContract]
    string GetInfo(string para); 
}
   [ServiceBehavior(
        InstanceContextMode = InstanceContextMode.Single)]
public partial class LEDSVCWIN : ILEDSVCWIN
{     
    public string GetInfo(string para)
    {
        string SReturn = "";
        try
        {
            XDocument xdoc = XDocument.Parse(para);
            Dictionary<string, string> dicSrcParamater = new Dictionary<string, string>();
            var items = from item in xdoc.Elements()
                        select item;
            List<XElement> clist = items.ToList<XElement>();
            string cmd = "";
            object result = null;
            foreach (XElement item in clist)
            {
                var itemsx = from itemx in item.Elements()
                             select itemx;
                foreach (XElement x in itemsx)
                {
                    dicSrcParamater.Add(x.Name.ToString(), (string)x.Value);
                    if (x.Name.ToString() == "COMMAND")
                    {
                        cmd = x.Value;
                    }
                }
            }

            result = SendLED(cmd, dicSrcParamater); 
            SReturn = result.ToString(); 
        }
        catch (Exception ex)
        {
            SReturn = ex.Message;
        }
        return SReturn;
    }
}
